package cn.supermaster.management.web.controller.system;

import cn.supermaster.management.web.service.system.ISDepartmentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.supermaster.management.common.controller.BaseController;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.rest.system
 * @ClassName: SystemDepartmentRestController
 * @Description: [部门信息]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/2/19 22:01
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Controller
@RequestMapping("/system/dept")
public class SystemDepartmentController extends BaseController {

    @Autowired
    private ISDepartmentService departmentService;

    @RequiresPermissions("system:dept:view")
    @GetMapping()
    public String skipDepartmentIndexHtml() {
        return departmentService.skipDepartmentIndexHtml();
    }

    /**
     * 新增部门
     */
    @GetMapping("/add/{parentId}")
    public String add(@PathVariable("parentId") Long parentId, ModelMap modelMap) {
        return departmentService.skipDepartmentAddHtml(modelMap, parentId);
    }


    /**
     * 修改
     */
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") Long deptId, ModelMap modelMap) {
        return departmentService.skipDepartmentModifyHtml(modelMap, deptId);
    }


    /**
     * 选择部门树
     *
     * @param deptId    部门ID
     * @param excludeId 排除ID
     */
    @GetMapping(value = {"/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}"})
    public String selectDeptTree(@PathVariable("deptId") Long deptId,
                                 @PathVariable(value = "excludeId", required = false) String excludeId,
                                 ModelMap modelMap) {
        return departmentService.skipBuildDepartmentTree(modelMap, deptId, excludeId);
    }
}
